// pages/biz/paySuccess/paySuccess.js
// import Serv from './paySuccessServ';
// var regeneratorRuntime = require("../../../../lib/js/runtime-module.js")
import Util from '../../../../utils/util.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 根据action的值改变显示内容: 1:秒杀-定金 ; 2:竞拍-报名费-竞拍中 ; 3:竞拍-报名费-未开始 4竞拍-定金
    action:2,
    countDownList: [],
    actEndTimeList: [],
    imgUrls:[],
    productDeType: [4, 5, 6, 7],
    productHouseType: [1, 2, 3]
  },

  // 点击下一步/返回
  nextTap(e){
    if(this.data.action == 2 ){
      let { seckillProductId } = this.data
      console.log('去竞拍')
      wx.navigateTo({
        url: `../../auctions/enterAuction/enterAuction?id=${seckillProductId}`,
      })
    } else if (this.data.action == 3){
      console.log('返回')
      wx.navigateTo({
        url: `../../auctions/auction/auction?seckillActivityId=${seckillActivityId}`,
      })
    }
  },

  goDetail: function (e) {
    let { seckillProductId,productId } = this.data
    wx.navigateTo({
      url: `/subPackages2/pages/auctions/auctionDetail/auctionDetail?id=${seckillProductId}&pid=${productId}`
    })
   
  },
  //查看订单
  toOrderDetail(){
    let { seckillActivityId} =this.data
    if(this.data.action == 1 ){
      let toDetailUlr = `/subPackages2/pages/kill/orderList/orderList?seckillActivityId=${seckillActivityId}&tabIndex=1`
      wx.redirectTo({
        url: toDetailUlr,
      })
    } else if (this.data.action == 4){
      let toDetailUlr = `/subPackages2/pages/auctions/orderList/orderList?seckillActivityId=${seckillActivityId}&tabIndex=1`
      wx.redirectTo({
        url: toDetailUlr,
      })
    }
  },
  toSalesTel(){
    let mobile = this.data.mobile
    wx.makePhoneCall({ phoneNumber: mobile })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    let tagList = options.tags ? JSON.parse(options.tags):''
    // if (tagList) {
    //   tagList = tagList.split(',')
    // }
    if (tagList && tagList.length >= 3) {
      tagList.splice(3, tagList.length - 1)
    }
    let seckillActivityId = wx.getStorageSync('seckillActivityId')
    this.setData({
      action: Number(options.actionType) || 1,
      price: options.price,
      imgUrls: options.imgUrls,
      seckillActivityId: seckillActivityId 
      // projectName: options.projectName,
      // detail: options.detail,
      // cityName: options.cityName,
      // provinceName: options.provinceName,
      // tagList,
      // seckillProductId: options.id,
      // productId:options.productId

    })
    console.log(tagList)
    if (options.actionType == 2) {
      this.setData({
        actionEndTime:options.time,
        seckillProductId: options.id
      })
      if (options.isStartActivity==1){
        this.setData({ action: 3 })
      }else{
        this.setData({ action: 2 })
      }
      // 执行倒计时函数
      this.countDown();
    } else if (options.actionType == 1 || options.actionType == 4){
      this.setData({ mobile: options.mobile})
    }
    let self = this
    wx.getStorage({
      key: 'currentDetail',
      success: function (res) {
        console.log(res)
        self.setData({
          detail: res.data
        })
      },
    })
  },
  timeFormat(param) {//小于10的格式化函数 
    return param < 10 ? '0' + param : param;
  },
  countDown() {//倒计时函数
    // 获取当前时间，同时得到活动结束时间数组
    let newTime = new Date().getTime();
    let endTime = this.data.actionEndTime;
    let countDownArr = [];
    
    // 对结束时间进行处理渲染到页面
    endTime = Util.dateFromString(endTime).getTime();
    let obj = null;
    // 如果活动未结束，对时间进行处理
    if (endTime - newTime > 0) {
      let time = (endTime - newTime) / 1000;
      // 获取天、时、分、秒
      let day = parseInt(time / (60 * 60 * 24));
      let hou = parseInt(time % (60 * 60 * 24) / 3600);
      let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
      let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
      obj = {
        day: this.timeFormat(day),
        hou: this.timeFormat(hou),
        min: this.timeFormat(min),
        sec: this.timeFormat(sec)
      }
    } else {//活动已结束，全部设置为'00'
      obj = {
        day: '00',
        hou: '00',
        min: '00',
        sec: '00'
      }
    }
    // 渲染，然后每隔一秒执行一次倒计时函数
    this.setData({ countDown: obj})
    //console.log(obj)
    let timeOut = setTimeout(this.countDown, 1000);
    this.setData({ timeOut: timeOut})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    clearTimeout(this.data.timeOut)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearTimeout(this.data.timeOut)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})